package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.handler.MessageContext;
import java.util.*;

@RestController
@Slf4j
@RequestMapping("/report")
public class Report {
    @Autowired
    private ReportService reportService;
    @Autowired
    private OrderService orderService;
    @GetMapping("/getMemberReport")

    public Result findreport( ){
     Map<String ,Object[]> num = reportService.findReportNumber();
        return new Result(true, MessageConst.GET_BUSINESS_REPORT_SUCCESS,num);
    }
    @GetMapping("/getSetmealReport")
    public Result findSetmealReport(){
        List<Map<String,Object>> setSetmealCount = orderService.findSetmealCount();
        List<String> setmealNames = new ArrayList<>();
        for (Map<String, Object> elem : setSetmealCount) {
            setmealNames.add(String.valueOf(elem.get("name")));

        }
        Map<String,Object> date = new HashMap<>();
        date.put("setmealNames",setmealNames);
        date.put("setmealCount",setSetmealCount);

     return new Result(true,MessageConst.GET_MEMBER_NUMBER_REPORT_SUCCESS,date);
    }
}
